import javax.swing.*;

public class mineSweeperFrame {
    private static String username="寂灭雷暴解构者";
    public static void main(String[] args) {
        homePage();
        JFrame frame = new JFrame("寂灭雷暴解构系统-"+username);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(1920, 1080);
        frame.setLocationRelativeTo(null);
        frame.setResizable(true);
        //首页
        mineSweeperhomePage homemenu = new mineSweeperhomePage(frame);
        frame.add(homemenu);
        frame.setVisible(true);
        //入口
    }
    public static void homePage(){
        String inputName= JOptionPane.showInputDialog(null,"请输入您的昵称:",
                "寂灭雷暴解构者",JOptionPane.PLAIN_MESSAGE);
        if(!inputName.equals("")){
            username = inputName.trim();
        }else{
            username = "寂灭雷暴解构者"; //玩家默认名为寂灭雷暴解构者
        }
    }
    //自选模式 闯关模式
    //自选模式入口为showMenu() 闯关模式可以设定五关卡（需思考闯关模式存在的意义）
    public static void showMenu(){
        int rows=9;
        int cols=9;
        int tntNum=10;
        String[] options={"简单(9×9,10雷)","中阶(16x16,40雷)","高阶(30×16，50雷)","自定义","退出经典模式"};
        int choices = JOptionPane.showOptionDialog(null,"玩家: "+username+" 请设置游戏难度:","游戏难度设置",JOptionPane.DEFAULT_OPTION,JOptionPane.INFORMATION_MESSAGE,null,options,options[0]);
        if(choices==0){
            rows=9;
            cols=9;
            tntNum=10;
        }else if(choices==1){
            rows=16;
            cols=16;
            tntNum=40;
        }else if(choices==2){
            rows=16;
            cols=30;
            tntNum=50;
        }else if(choices==3){
            try{
                String inputRows,inputCols,inputTnt;
                inputRows=JOptionPane.showInputDialog(null, "请输入行数(最小9,最大24):", "自定义行数", JOptionPane.PLAIN_MESSAGE);
                inputCols=JOptionPane.showInputDialog(null, "请输入列数(最小9,最大30):", "自定义列数", JOptionPane.PLAIN_MESSAGE);
                inputTnt=JOptionPane.showInputDialog(null, "请输入地雷数量:", "自定义地雷数量", JOptionPane.PLAIN_MESSAGE);

                rows=Integer.parseInt(inputRows.trim());
                cols=Integer.parseInt(inputCols.trim());
                tntNum=Integer.parseInt(inputTnt.trim());
                //判断输入值是否有效
                if(rows<9||rows>24){
                    rows=9;
                }
                if(cols<9||cols>30){
                    cols=9;
                }
                if(tntNum<1||tntNum>=(rows*cols)){
                    tntNum=10;
                }
            }catch (Exception e){
                JOptionPane.showMessageDialog(null, "输入无效，使用默认初级设置9*9。");
                //rows = 9;cols = 9;tntNum = 10;
            }
        }else if(choices==4){
            //System.exit(0);
            return;
        }
        JFrame frame = new JFrame("寂灭雷暴解构者 - 玩家:"+username);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        gamePanel panel = new gamePanel(rows,cols,tntNum);
        frame.setContentPane(panel);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

